﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luna.NHibernate;
using XWord.Fundamental.Domain.Model;
using uNhAddIns.Adapters;
using System.Collections;

namespace XWord.Fundamental.Domain.Impl
{
    [PersistenceConversational(MethodsIncludeMode = MethodsIncludeMode.Implicit)]
    public class ArticleModel : IArticleModel
    {
        private readonly IRepository<RCArticle> _rcArticleRepository;
        private readonly IRepository<LCArticle> _lcArticleRepository;
        private readonly IRepository<Translate> _translateRepository;
        public ArticleModel(IRepository<RCArticle> rcArticleRepository, IRepository<LCArticle> lcArticleRepository,
            IRepository<Translate> translateRepository)
        {
            _rcArticleRepository = rcArticleRepository;
            _lcArticleRepository = lcArticleRepository;
            _translateRepository = translateRepository;
        }

        public IList<RCArticle> GetRCArticleList()
        {
            return _rcArticleRepository.GetAll().OrderByDescending(e => e.CreateTime).ToList();
        }

        public IList<LCArticle> GetLCArticleList()
        {
            return _lcArticleRepository.GetAll().OrderByDescending(e => e.CreateTime).ToList();
        }

        #region IArticleModel Members


        public IEnumerable GetTranslateList()
        {
            var dict = _translateRepository.GetAll().GroupBy(p => p.CreateTime);
            return dict;
            // return _translateRepository.GetAll().OrderByDescending(e => e.CreateTime).ToList();
        }


        [PersistenceConversation(ConversationEndMode = EndMode.CommitAndContinue)]
        public void SaveRCArticle(RCArticle art)
        {
            _rcArticleRepository.MakePersistent(art);
        }

        [PersistenceConversation(ConversationEndMode = EndMode.CommitAndContinue)]
        public void SaveLCArticle(LCArticle art)
        {
            _lcArticleRepository.MakePersistent(art);
        }

        #endregion
    }
}
